Socket
Socket
Sign inDemoInstall

unstorage

Package Overview
Dependencies
156
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    unstorage

Universal Storage Layer


Version published
Weekly downloads
838K
decreased by-3.47%
Maintainers
1
Created
Weekly downloads
 

Package description

What is unstorage?

The 'unstorage' npm package is a versatile storage utility that provides a unified API for interacting with various storage backends. It allows developers to easily switch between different storage mechanisms such as local storage, session storage, and even remote storage solutions without changing the core logic of their applications.

What are unstorage's main functionalities?

Local Storage

This feature allows you to interact with local storage using a simple API. You can set, get, and remove items from local storage.

const { createStorage } = require('unstorage');
const localStorage = createStorage();

// Set a value
await localStorage.setItem('key', 'value');

// Get a value
const value = await localStorage.getItem('key');
console.log(value); // Outputs: 'value'

// Remove a value
await localStorage.removeItem('key');

Session Storage

This feature allows you to interact with session storage using the same API as local storage. You can set, get, and remove items from session storage.

const { createStorage } = require('unstorage');
const sessionStorage = createStorage({ driver: 'session' });

// Set a value
await sessionStorage.setItem('key', 'value');

// Get a value
const value = await sessionStorage.getItem('key');
console.log(value); // Outputs: 'value'

// Remove a value
await sessionStorage.removeItem('key');

Remote Storage

This feature allows you to interact with remote storage solutions via HTTP. You can set, get, and remove items from a remote storage backend.

const { createStorage } = require('unstorage');
const remoteStorage = createStorage({ driver: 'http', baseURL: 'https://api.example.com/storage' });

// Set a value
await remoteStorage.setItem('key', 'value');

// Get a value
const value = await remoteStorage.getItem('key');
console.log(value); // Outputs: 'value'

// Remove a value
await remoteStorage.removeItem('key');

Other packages similar to unstorage

Changelog

Source

v1.10.2

compare changes

🩹 Fixes

  • http, server: Handle missing resources with http 404 (#367)
  • pkg: Make ioredis dependency optional (#410)
  • vercel-kv: Add missing driver name (#355)
  • setItems: Call driver native setItems only to avoid duplicate write (#392)
  • getItems, setItems types (#395)

💅 Refactors

  • cloudflare-kv, cloudflare-r2: Move getBindings to utils and add default BUCKET for r2 (#292)
  • netlify-blobs: Update to v7 (#407)

📖 Documentation

  • planetscale: Correct table option name (#359)
  • vercel-kv: Fix typo (#362)
  • Refactor with unjs-docs and nuxt ui pro (#374)
  • Improvements (a64e941)
  • Fix links and add redirects (166498f)
  • Update unjs-docs version and add redirects (f2a408d)
  • Fix typo in http-server (#385)
  • Update deps (bfbf423)
  • Update link (#408)

📦 Build

  • Update mkdist for cjs dist hotfix (cae8533)

🏡 Chore

✅ Tests

  • Skip netlify-blobs for now (75b2353)
  • http: Add tests for null value (#365)

❤️ Contributors

Readme

Source

💾 Unstorage

npm version npm downloads Codecov bundle License

Unstorage provides an async Key-Value storage API with conventional features like multi driver mounting, watching and working with metadata, dozens of built-in drivers and a tiny core.

👉 Documentation

Features

  • Designed for all environments: Browser, NodeJS, and Workers
  • Lots of Built-in drivers
  • Asynchronous API
  • Unix-style driver mounting to combine storages
  • Default in-memory storage
  • Tree-shakable utils and tiny core
  • Auto JSON value serialization and deserialization
  • Binary and raw value support
  • State snapshots and hydration
  • Storage watcher
  • HTTP Storage with built-in server

Usage

Install unstorage npm package:

# yarn
yarn add unstorage

# npm
npm install unstorage

# pnpm
pnpm add unstorage
import { createStorage } from "unstorage";

const storage = createStorage(/* opts */);

await storage.getItem("foo:bar"); // or storage.getItem('/foo/bar')

👉 Check out the the documentation for usage information.

Contribution

  • Clone repository
  • Install dependencies with pnpm install
  • Use pnpm dev to start jest watcher verifying changes
  • Use pnpm test before pushing to ensure all tests and lint checks passing

License

MIT

FAQs

Last updated on 14 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc